<?php

namespace app\zyhsapi\model;


use think\Exception;

class ZyhsRecordShareAdd extends BaseCacheZyhs
{
    protected $table = 'good_wechat.zyhs_record_share_add';

    protected $noNeedJudgeSummer = ['香港特别行政区', '澳门特别行政区', '台湾省', '北美洲', '大洋洲', '非洲', '南美洲', '欧洲', '亚洲', ''];

    protected $setting = [
        'natal' => [
            'planet' => [
                [1, 8.5], [1, 7.5], [1, 3.5], [1, 3.5], [1, 4], [1, 4.5], [1, 4.5], [1, 2.5], [1, 2.5], [1, 2.5],
                [0, 0], [0, 0], [0, 0], [0, 0], [1, 2.5], [0, 0], [0, 0], [1, 2.5], [1, 2.5], [1, 2.5], [1, 2.5],
            ],
            'phase' => [
                0 => [1, 0], 60 => [1, 0], 90 => [1, 0], 120 => [1, 0], 180 => [1, 0],
                45 => [0, 0], 135 => [0, 0], 30 => [0, 0], 150 => [0, 0], 72 => [0, 0], 144 => [0, 0],
            ],
            'arabic' => [
                [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0],
                [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0],
                [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0],
            ],
            'h_sys' => 'p',
            'firdaria' => 'default',
            'bound_type' => 'default',
            'ecliptic' => 0,
            'profection_push_direction' => 0,
            'decanates' => 0,
            'ayanamsa' => 0,
            'location_use' => 0,
        ],
    ];

    /**
     * 档案是否添加过了
     * @param int $type 1=>微信 2=>QQ
     * @param string $code 用户身份标识
     * @param int $time 分享时间|分享标识
     * @return bool true 已添加 false未添加过
     */
    public function hasAddRecord(int $type, string $code, int $time): bool
    {
        try
        {
            $data = $this->where('type', $type)->where('code', $code)->where('time', $time)->field('id')->find();
        }
        catch (Exception $e)
        {
            $data = null;
        }

        return $data ? true : false;
    }

    /**
     * 插入数据
     * @param $map
     * @return bool|int
     */
    public function SaveData($map)
    {
        try
        {
            $id = $this->insertGetId($map);
        }
        catch (\Exception $e)
        {
            return false;
        }
        return $id;
    }
}
